

class NeighborRouter(object):
    total_number = 0

    def __init__(self):
        self.interfaces = []
        self.index = self.total_number
        NeighborRouter.total_number += 1

class Interface(object):
    def __init__(self, router_id, index):
        self.index = index
        self.router_id = router_id
        self.adj_interfaces = []


def gen_tree_lan_topo(routers, max_intf_num, max_transit_router_num):
    next_idle_router_index = 1
    for index, router in enumerate(routers):
        child_intf_num = max_intf_num - 1 if index else max_intf_num
        for intf_index in range(child_intf_num):
            parent_intf = Interface(router.index, len(router.interfaces))
            router.interfaces.append(parent_intf)
            for transit_index in range(max_transit_router_num):
                if next_idle_router_index < len(routers):
                    child = routers[next_idle_router_index]
                    child_intf = Interface(child.index, len(child.interfaces))
                    child_intf.adj_interfaces.append(parent_intf)
                    child.interfaces.append(child_intf)
                    parent_intf.adj_interfaces.append(child_intf)
                    next_idle_router_index += 1
                else:
                    return

if __name__ == '__main__':
    routers = [NeighborRouter() for i in range(10)]
    gen_tree_lan_topo(routers, 3, 3)